﻿using System;
using System.Web.Mvc;

namespace BabyShop.WebSite.Exts.Attributes
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public class UserAuthorizeAttribute : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
                throw new ArgumentNullException("filterContext");

            if (filterContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(GeneralPermissionAttribute), true).Length > 0
                || filterContext.ActionDescriptor.GetCustomAttributes(typeof(GeneralPermissionAttribute), true).Length > 0)
                return;

            /*if (PersistentDataContainer.Current.Read<User>() == default(User))
                filterContext.Result = new HttpUnauthorizedResult();*/            
        }
    }
}